package com.course.service;

import com.course.dao.TeacherDAO;
import com.course.entity.Teacher;

import java.util.List;

public class TeacherService {
    private final TeacherDAO teacherDAO = new TeacherDAO();

    public Teacher login(String username, String password) {
        Teacher teacher = teacherDAO.findByUsername(username);
        if (teacher != null && teacher.getPassword().equals(password)) {
            return teacher;
        }
        return null;
    }

    // 获取所有老师列表（不包括密码）
    public List<Teacher> getAllTeachers() {
        return teacherDAO.getAllTeachers();
    }

    public void addTeacher(Teacher teacher) {
        teacherDAO.addTeacher(teacher);
    }

    public Teacher findById(int id) {
        return teacherDAO.findById(id);
    }

    public void updateTeacher(Teacher teacher) {
        teacherDAO.updateTeacher(teacher);
    }

    // 更新教师密码
    public boolean updatePassword(int teacherId, String newPassword) {
        return teacherDAO.updatePassword(teacherId, newPassword);
    }

    // 根据工号、姓名、院系搜索老师
    public List<Teacher> searchTeachers(String teacherNumber, String teacherName, String department) {
        return teacherDAO.searchTeachers(teacherNumber, teacherName, department);
    }

    // 根据工号、密码和邮箱进行老师登录
    public Teacher loginByTeacherNumberPasswordAndEmail(String teacherNumber, String password, String email) {
        return teacherDAO.findTeacherByTeacherNumberPasswordAndEmail(teacherNumber, password, email);
    }
} 